package com.xayy.core.antlr4.listener;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dongxingli
 * createTime 2020/6/3
 * @version V1.0
 */
@Slf4j
@Getter
public class GrammarErrorListener extends BaseErrorListener {

    private List<String> errMessage = new ArrayList<>(0);

    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
        String message = String.format("行%s列%s非法符号: %s. 原始原因:%s", line, charPositionInLine, offendingSymbol, msg);
        errMessage.add(message);
    }
}
